package com.homegoods;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSON;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.AbstractMainActivity;
import com.kedll.library.databinding.ActivityMainBinding;
import com.kedll.library.listener.IHomeDataHelper;
import com.kedll.library.location.LocationInterface;
import com.network.update.IGetUpdateInfo;
import com.network.utils.UpdateUtil;

import java.util.concurrent.TimeUnit;

import io.reactivex.Flowable;

/**
 * @author QiQi
 * @ClassName: MainActivity
 * @date 2018/9/2
 * @description
 */
@Route(path = ARouterPath.PATH_MAIN_HOME)
public class MainActivity extends AbstractMainActivity<ActivityMainBinding> {

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        lowBar.setBackgroundColor(Color.WHITE);
        onSoftWareUpdate();
    }

    @SuppressLint("CheckResult")
    private void onSoftWareUpdate() {
        Flowable.timer(2, TimeUnit.SECONDS)
                .compose(this.bindToLifecycle())
                .subscribe(o -> UpdateUtil.softWareUpdate(MainActivity.this, getSupportFragmentManager(), false, new IGetUpdateInfo() {
                    @Override
                    public boolean isUpgrade(JSON d) {
                        return false;
                    }

                    @Override
                    public String getUpdateInfo(JSON d) {
                        return null;
                    }

                    @Override
                    public String getUpdateUrl(JSON d) {
                        return null;
                    }
                }));
    }

    @Override
    protected LocationInterface getLocationInterface() {
        return null;
    }

    @Override
    protected IHomeDataHelper getDataHelper() {

        return new IHomeDataHelper() {
            @Override
            public int[] getTabBarNormalIcon() {
                return new int[]{
                        R.mipmap.home_normal,
                        R.mipmap.classify_normal,
                        /*R.mipmap.discover_normal,*/   /*del shibo.zheng 19/06/25*/
                        R.mipmap.shopping_car_normal,
                        R.mipmap.my_normal
                };
            }

            @Override
            public int[] getTabBarPressIcon() {
                return new int[]{
                        R.mipmap.home_press,
                        R.mipmap.classify_press,
                        /*R.mipmap.discover_press,*/    /*del shibo.zheng 19/06/25*/
                        R.mipmap.shopping_car_press,
                        R.mipmap.my_press
                };
            }

            @Override
            public String[] getFragmentName() {
                return new String[]{
                        ARouterPath.PATH_FRAGMENT_HOME,
                        ARouterPath.PATH_FRAGMENT_CLASSIFY,
                        /*ARouterPath.PATH_FRAGMENT_DISCOVER,*/    /*del shibo.zheng 19/06/25*/
                        ARouterPath.PATH_FRAGMENT_SHOPPING,
                        ARouterPath.PATH_FRAGMENT_MY};
            }

            @Override
            public String[] getTabMenuName(Context ctx) {
                return ctx.getResources().getStringArray(R.array.menu_name);
            }

            @Override
            public int getNormalTextColor() {
                return ContextCompat.getColor(MainActivity.this, R.color.color_aaaaaa);
            }

            @Override
            public int getSelectTextColor() {
                return ContextCompat.getColor(MainActivity.this, R.color.color_a541c9);
            }

        };

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        lowBar.setCurrentItem(0);
    }

}